package com.spring.rabbitmq.routing.topic;

import com.rabbitmq.client.*;
import com.spring.rabbitmq.utils.RabbitMQUtils;
import lombok.SneakyThrows;

import java.io.IOException;

/**
 * @Author: lzx
 * @Data: 2021/04/29/10:25
 * @Description：
 */
public class Customer1 {
    @SneakyThrows
    public static void main(String[] args) {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明队列
        channel.exchangeDeclare("topics", "topic");
        //临时队列
        String queue = channel.queueDeclare().getQueue();
        //*通配符 匹配一个词
        channel.queueBind(queue, "topics", "user.*");
        //消费消息
        channel.basicConsume(queue, true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1：" + new String(body));
            }
        });


    }
}
